package xinyou.jh.net
{
	import alert.Alert;
	
	import flash.events.Event;
	
	import xinyou.jh.net.packet.JHPacket;
	import xinyou.net.ByteArrayEX;
	import xinyou.net.SocketConnection;
	import xinyou.net.packet.IHead;
	
	public class JHSocketConnection extends SocketConnection
	{
		public function JHSocketConnection()
		{
			super(new JHPacket());
		}
		override protected function socketconnect(event:Event) : void
		{
			dispatchEvent(event);
			t1("连接服务器成功");
		}
		override protected function socketClose(event:Event) : void 
		{
			dispatchEvent(event);
			if(this == SocketManager.getInstance().mainSocket)
			{
				Alert.show("与主服务器断开连接...","提示");
			}
		}
		override protected function ioErrorHandler(event:Event) : void 
		{
			dispatchEvent(event);
			t0("连接错误");
		}
		override protected function securityErrorHandler(event:Event) : void 
		{
			dispatchEvent(event);
			t0("连接错误");
		}
		override protected function makePacket(head:IHead,data:ByteArrayEX,length:uint):void
		{
			t1("收到到消息，命令号为："+head.cmds+"，内容长度："+(length - head.headLength)+"，实际长度："+(data.length-6));
			super.makePacket(head,data,length);
		}
		override public function close():void
		{
			super.close();
			t1("客户端主动断开连接，断开的socket是："+this);
		}
	}
}